﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_StockController : BaseApiController
    {
        #region DI

        public PB_StockController(IPB_StockBusiness pB_StockBus)
        {
            _pB_StockBus = pB_StockBus;
        }

        IPB_StockBusiness _pB_StockBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_Stock>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_StockBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 获取库存数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<PageResult<InventoryDataDTO>> GetInventoryData(PageInput<QueryGetInventoryDTO> input)
        {
            return await _pB_StockBus.GetInventoryData(input);
        }
        /// <summary>
        /// 货区库存详细数量
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<InventoryDetalDTO>> GetInventorydetalData(PageInput<QueryGetInventoryDTO> input)
        {
            return await _pB_StockBus.GetInventorydetalData(input);
        }


        [HttpPost]
        public async Task<PB_Stock> GetTheData(IdInputDTO input)
        {
            return await _pB_StockBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 上架入库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task Warehousing(PB_StockDTOquery query)
        {
            await _pB_StockBus.Warehousing(query);
        }

        [HttpPost]
        public PageResult<ReturnManagementDTO> WarehousingManagement(ManagementQueryDTO queryDTO)
        {
            return _pB_StockBus.WarehousingManagement(queryDTO);
        }
        [HttpGet]
        public StockDataInfoDTO GetWarehousingManagement(string ReceiptdocNo)
        {
            return _pB_StockBus.GetWarehousingManagement(ReceiptdocNo);
        }

        
        /// <summary>
        /// 获取要拆包的成品
        /// </summary>
        /// <param name="JobBookingqrcode">成品二维码</param>
        /// <param name="packqrcode">要拆包的二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PackListDetailDTO> GetJobBookingData(string JobBookingqrcode, string packqrcode)
        {
            return await _pB_StockBus.GetJobBookingDataAsync(JobBookingqrcode, packqrcode);
        }

        /// <summary>
        /// 拆包获取包的信息
        /// </summary>
        /// <param name="packqrcode">包二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PackListDTO> GetPackData(string packqrcode)
        {
            return await _pB_StockBus.GetPackDataAsync(packqrcode);
        }

        /// <summary>
        /// 拆包提交信息(全局变量为true)
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PackListDTO> UnpackingData(UnpackingDataDTO data)
        {
            return await _pB_StockBus.UnpackingDataAsync(data);
        }

        /// <summary>
        /// 拆包提交信息(全局变量为false)
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UnpackingPackData(UnpackingPackDTO data)
        {
            await _pB_StockBus.UnpackingPackDataAsync(data);
        }

        /// <summary>
        /// 扫描合并包
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PackListDTO> GetNewPackData(UnpackingDataDTO data)
        {
            return await _pB_StockBus.GetNewPackDataAsync(data);
        }

        /// <summary>
        /// 合并提交信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PackListDTO> MergeUnpackingData(UnpackingDataDTO data)
        {
            return await _pB_StockBus.MergeUnpackingDataAsync(data);
        }


        #endregion

        #region  SKU管理合并包

        /// <summary>
        /// 合并包扫描成品物料信息
        /// </summary>
        /// <param name="JobQrCode">成品二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PackListDetailDTO> GetMergePackListDetailData(string JobQrCode)
        {
            return await _pB_StockBus.GetMergePackListDetailDataAsync(JobQrCode);
        }

        /// <summary>
        /// 合并包保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveMergePackListDetail(MergePackListDetail data)
        {
            await _pB_StockBus.SaveMergePackListDetailAsync(data);
        }


        #endregion

        #region  移库

        /// <summary>
        /// 获取库里的包信息
        /// </summary>
        /// <param name="packqrcode">包二维码</param>
        /// <param name="LocalQrCode">货位二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MovePackListDTO> GetStockPackData(string packqrcode, string LocalQrCode)
        {
            return await _pB_StockBus.GetStockPackDataAsync(packqrcode, LocalQrCode);
        }

        /// <summary>
        /// 获取单个物料信息
        /// </summary>
        /// <param name="MaterialQrCode">物料二维码</param>
        /// <param name="LocalQrCode">货位二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MovePackListDTO> GetMoveMaterialData(string MaterialQrCode, string LocalQrCode)
        {
            return await _pB_StockBus.GetMoveMaterialDataAsync(MaterialQrCode, LocalQrCode);
        }

        /// <summary>
        /// 获取单个成品物料信息
        /// </summary>
        /// <param name="JobQrCode">成品二维码</param>
        /// <param name="LocalQrCode">货位二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MovePackListDTO> GetMoveJobData(string JobQrCode, string LocalQrCode)
        {
            return await _pB_StockBus.GetMoveJobDataAsync(JobQrCode, LocalQrCode);
        }

        /// <summary>
        /// 移库操作
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task TransferLibraryData(TransferLibraryDTO data)
        {
            await _pB_StockBus.TransferLibraryDataAsync(data);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Stock data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_StockBus.AddDataAsync(data);
            }
            else
            {
                await _pB_StockBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_StockBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}